package com.jade.linkong.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jade.common.annotation.Log;
import com.jade.common.enums.BusinessType;
import com.jade.linkong.domain.LkPenalties;
import com.jade.linkong.service.ILkPenaltiesService;
import com.jade.common.core.controller.BaseController;
import com.jade.common.core.domain.AjaxResult;
import com.jade.common.utils.poi.ExcelUtil;
import com.jade.common.core.page.TableDataInfo;

/**
 * 考核Controller
 * 
 * @author jade
 * @date 2020-07-15
 */
@Controller
@RequestMapping("/linkong/penalties")
public class LkPenaltiesController extends BaseController
{
    private String prefix = "linkong/penalties";

    @Autowired
    private ILkPenaltiesService lkPenaltiesService;

    @RequiresPermissions("penalties:penalties:view")
    @GetMapping()
    public String penalties()
    {
        return prefix + "/penalties";
    }

    /**
     * 查询考核列表
     */
    @RequiresPermissions("penalties:penalties:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LkPenalties lkPenalties)
    {
        startPage();
        List<LkPenalties> list = lkPenaltiesService.selectLkPenaltiesList(lkPenalties);
        return getDataTable(list);
    }

    /**
     * 导出考核列表
     */
    @RequiresPermissions("penalties:penalties:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LkPenalties lkPenalties)
    {
        List<LkPenalties> list = lkPenaltiesService.selectLkPenaltiesList(lkPenalties);
        ExcelUtil<LkPenalties> util = new ExcelUtil<LkPenalties>(LkPenalties.class);
        return util.exportExcel(list, "penalties");
    }

    /**
     * 新增考核
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存考核
     */
    @RequiresPermissions("penalties:penalties:add")
    @Log(title = "考核", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LkPenalties lkPenalties)
    {
        return toAjax(lkPenaltiesService.insertLkPenalties(lkPenalties));
    }

    /**
     * 修改考核
     */
    @GetMapping("/edit/{lkPenaltiesId}")
    public String edit(@PathVariable("lkPenaltiesId") Long lkPenaltiesId, ModelMap mmap)
    {
        LkPenalties lkPenalties = lkPenaltiesService.selectLkPenaltiesById(lkPenaltiesId);
        mmap.put("lkPenalties", lkPenalties);
        return prefix + "/edit";
    }

    /**
     * 修改保存考核
     */
    @RequiresPermissions("penalties:penalties:edit")
    @Log(title = "考核", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LkPenalties lkPenalties)
    {
        return toAjax(lkPenaltiesService.updateLkPenalties(lkPenalties));
    }

    /**
     * 删除考核
     */
    @RequiresPermissions("penalties:penalties:remove")
    @Log(title = "考核", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lkPenaltiesService.deleteLkPenaltiesByIds(ids));
    }
}
